import requests
from lxml import etree
from bs4 import BeautifulSoup
cookies = {
    'zkhanecookieclassrecord': '%2C54%2C',
}

headers = {
'Connection':'close',

    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
}

response = requests.get('https://pic.netbian.com/4kdongman/', headers=headers)
response.encoding="gbk"
response=response.text



tree=etree.HTML(response)
# n拿到全部的li标签
ul=tree.xpath('//*[@id="main"]/div[3]/ul/li')

for li in ul:
    img_title = li.xpath('./a/b/text()')[0]+'.jpg'
    img_detail='https://pic.netbian.com'+li.xpath('./a/@href')[0]
    #print(img_title,img_detail)
    page_detail=requests.get(img_detail,headers=headers)
    page_detail.encoding = "gbk"
    page_detail = page_detail.text
    detail_tree=etree.HTML(page_detail)
    # n拿到全部的li标签
    img_src = 'https://pic.netbian.com'+detail_tree.xpath('//*[@id="img"]/img/@src')[0]
    re=requests.get(img_src,headers=headers).content
    with open('./picture/'+img_title,'wb') as fp:
        fp.write(re)
        print(img_title+"爬取成功")


